All Questions
Tagged with sortingcomplexity
23 questions
2votes
1answer
60views
Merge Sort with Minimum Sufficient Variables, Verbosity and better Space Complexity
The majority of merge sort implementations searched online are provided with unnecessary variables and code lines. Here is an attempt to reduce that. However, does passing back the subArray as return ...
4votes
1answer
728views
Performant Sort function for big arrays
In sort(arr), I want to sort an array. Children must be beneath their parent. And children of the same parent are sorted using ...
7votes
2answers
151views
Determine the complexity of sorting a binary array
The challenge is to sort an integer array containing only ones and zeros with the lowest complexity possible. As always, I am interested in any improvements suggested but in this question I am most ...
2votes
1answer
71views
In-Place Merging of Two Bubble Sorted Linked Lists (Python)
I'm following a tutorial on merging two bubble-sorted Single Linked Lists in Python. merge1 does the merging by creating a new list with maybe \$O(N+M)\$ memory ...
1vote
1answer
4kviews
The quicksort algorithm in Haskell
I am learning Haskell programming language mainly from this source. And there I have encouraged with "an elegant" realization of the quicksort sorting algorithm (the Quick, sort! section). ...
6votes
5answers
3kviews
Sort an array of 0s, 1s and 2s in Java
Write a program to sort an array of 0's,1's and 2's in ascending order. Input: The first line contains an integer 'T' denoting the total number of test cases. In each test cases, First ...
1vote
2answers
191views
Checking whether two lists contain the same elements
I have two lists of numbers: $$\{i_1, i_2, i_3,i_4\}$$ and $$\{j_1,j_2,j_3,j_4\}$$ The problem I want to solve is: Inside a loop, if the following two conditions are satisfied, then it will do ...
0votes
2answers
608views
Pancake sort inteview using java
Given an array of integers arr: Write a function flip(arr, k) that reverses the order of the first k elements in the array <...
4votes
2answers
900views
Bottom-up singly linked list merge sort in C++
This is an implementation of a singly linked list merge sort I did on paper during a job interview recently, using a bottom-up approach. The requirement was simply "implement a merge sort for a ...
0votes
1answer
1kviews
Sort multidimensional array based of the difference in the value
Sort multidimensional array based of the difference in the value, if value is same sort on first column. Constrains: No of rows can be any but fixed no of column ie 2. Example: <...
-5votes
1answer
228views
Category of sorting algorithm and complexity [closed]
Just for fun, I wrote a sorting algorithm. I did not compare this with existing sorting algorithms.Can someone tell me what class of sorting algorithm this is and it's complexity? The algorithm ...
3votes
1answer
5kviews
Calculating the most profit from an array of stock prices
I'm a newbie learning how to code, and I am trying to find the most efficient way to calculate the most profit from an array of stock prices. For a given array,I have a list of stock prices over n ...
5votes
2answers
2kviews
Non-recursive implementation of MergeSort
I've been trying to internalize some of the basic sorting algorithms recently, and to do so I've been looking at their wikipedia pages to refresh myself with how they work, and then coding my own "...
1vote
1answer
153views
Merge sort C# time and space efficiency
Please comment on time and space efficiency. ...
5votes
1answer
6kviews
Sort a given string in ascending order
This code sort the string below in ascending order. I'd prefer it split-up in two or three smaller, simpler methods. I'm also wondering whether my algorithm has a decent time complexity. Given string ...